package com.seeyon.ctp.rest.resources;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.service.ReceptionSalesOrderService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.*;

/**
 * 接收销售订单数据接口
 */
@Path("brwh")
@Produces({"application/json"})
@Consumes({"application/json"})
public class ReceptionSalesOrderResources extends BaseResource {
    private static final Log log = CtpLogFactory.getLog(ReceptionSalesOrderResources.class);
    private ReceptionSalesOrderService rs = (ReceptionSalesOrderService) AppContext.getBean("receptionSalesOrderService");

    /**
     * 新建待发任务(待发)
     *
     * @param param 请求参数，格式为Map<String, Object>
     * @return Response 返回响应对象
     * @throws Exception 异常处理
     */
    @POST
    @Path("reception/salesOrder")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response receptionSalesOrder(Map<String, Object> param) {
        HashMap<String, Object> reualtMap = new HashMap<String, Object>();
        try {
            log.info("获取到的rs：" + rs);
            reualtMap = rs.receptionSalesOrder(param);
        } catch (Exception e) {
            log.error("处理销售订单数据异常：", e);
            reualtMap.put("code", 500);
            reualtMap.put("data", "");
            reualtMap.put("msg", "处理销售订单数据异常：" + e.getMessage());
        }
        return this.ok(JSONObject.toJSONString(reualtMap));
    }
}
